package com.eims.ball.info.fragment;


import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;
import bls.juejin.cn.R;


public class FenxiOneFragment extends Fragment implements OnClickListener {
	private Activity activity;
	private TextView tvJiben, tvZhenron, tvJishu;
	public int tvId;
	private String infoId,hid,gid, mainName, GuesName;



	public FenxiOneFragment() {
		super();
	}

	public static FenxiOneFragment newInstance(String infoId,String hid,String gid,String mainName,String GuesName) {

		Bundle args = new Bundle();

		FenxiOneFragment fragment = new FenxiOneFragment();

		args.putString("infoId",infoId);
		args.putString("hid",hid);
		args.putString("gid",gid);
		args.putString("mainName",mainName);
		args.putString("GuesName",GuesName);
		fragment.setArguments(args);
		return fragment;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fenxi_fragment, container, false);
		activity = getActivity();

		Bundle args = getArguments();
		if (args != null) {
			this.infoId = args.getString("infoId");
			this.hid= args.getString("hid");
			this.gid = args.getString("gid");
			this.mainName= args.getString("mainName");
			this.GuesName= args.getString("GuesName");

		}


		init(view);
		changeFragment(1);
		
		return view;
	}

	private void init(View view) {
		// TODO Auto-generated method stub
		tvJiben = (TextView) view.findViewById(R.id.tv_jibenmain);
		tvZhenron = (TextView) view.findViewById(R.id.tv_zhenronmian);
		tvJishu = (TextView) view.findViewById(R.id.tv_jishumain);
		tvJiben.setOnClickListener(this);
		tvZhenron.setOnClickListener(this);
		tvJishu.setOnClickListener(this);

	}

	public void changeFragment(int i) {
		if (i == 1) {
			tvId = R.id.tv_jibenmain;
			tvJiben.setBackgroundResource(R.color.main_red);
			tvZhenron.setBackgroundResource(R.color.main_write);
			tvJishu.setBackgroundResource(R.color.main_write);
			
			tvJiben.setTextColor(activity.getResources().getColor(R.color.main_write));
			tvZhenron.setTextColor(activity.getResources().getColor(R.color.main_peilv));
			tvJishu.setTextColor(activity.getResources().getColor(R.color.main_peilv));
			
			FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
			transaction.replace(R.id.fragment_container,  FenxiJibenFragment.newInstance(infoId,hid,gid,mainName,GuesName), "jiben");

			transaction.commitAllowingStateLoss();

		} else if (i == 2) {
			tvId = R.id.tv_zhenronmian;
			tvJiben.setBackgroundResource(R.color.main_write);
			tvZhenron.setBackgroundResource(R.color.main_red);
			tvJishu.setBackgroundResource(R.color.main_write);
			tvJiben.setTextColor(activity.getResources().getColor(R.color.main_peilv));
			tvZhenron.setTextColor(activity.getResources().getColor(R.color.main_write));
			tvJishu.setTextColor(activity.getResources().getColor(R.color.main_peilv));
			FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
			transaction.replace(R.id.fragment_container, FenxiZhengrongFragment.newInstance(infoId,hid,gid,mainName,GuesName), "zhenron");

			transaction.commitAllowingStateLoss();

		} else {
			tvId = R.id.tv_jishumain;
			tvJiben.setBackgroundResource(R.color.main_write);
			tvZhenron.setBackgroundResource(R.color.main_write);
			tvJishu.setBackgroundResource(R.color.main_red);
			tvJiben.setTextColor(activity.getResources().getColor(R.color.main_peilv));
			tvZhenron.setTextColor(activity.getResources().getColor(R.color.main_peilv));
			tvJishu.setTextColor(activity.getResources().getColor(R.color.main_write));
			FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
			transaction.replace(R.id.fragment_container,  FenxiJishuFragment.newInstance(infoId,hid,gid,mainName,GuesName), "jishu");

			transaction.commitAllowingStateLoss();

		}
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.tv_jibenmain:
			if (tvId != R.id.tv_jibenmain) {
				changeFragment(1);
			}
			break;
		case R.id.tv_zhenronmian:
			if (tvId != R.id.tv_zhenronmian) {
				changeFragment(2);
			}
			break;
		case R.id.tv_jishumain:
			if (tvId != R.id.tv_jishumain) {
				changeFragment(3);
			}
			break;

		default:
			break;
		}
	}

}
